package com.moxiao.yfjh.module.blind.controller.admin.memberSeeme;

import static com.moxiao.yfjh.framework.common.pojo.CommonResult.success;
import static com.moxiao.yfjh.framework.operatelog.core.enums.OperateTypeEnum.EXPORT;

import com.moxiao.yfjh.framework.common.pojo.CommonResult;
import com.moxiao.yfjh.framework.common.pojo.PageResult;
import com.moxiao.yfjh.framework.excel.core.util.ExcelUtils;
import com.moxiao.yfjh.framework.operatelog.core.annotations.OperateLog;
import com.moxiao.yfjh.module.blind.controller.admin.memberSeeme.vo.MemberSeemeCreateReqVO;
import com.moxiao.yfjh.module.blind.controller.admin.memberSeeme.vo.MemberSeemeExcelVO;
import com.moxiao.yfjh.module.blind.controller.admin.memberSeeme.vo.MemberSeemeExportReqVO;
import com.moxiao.yfjh.module.blind.controller.admin.memberSeeme.vo.MemberSeemePageReqVO;
import com.moxiao.yfjh.module.blind.controller.admin.memberSeeme.vo.MemberSeemeRespVO;
import com.moxiao.yfjh.module.blind.controller.admin.memberSeeme.vo.MemberSeemeUpdateReqVO;
import com.moxiao.yfjh.module.blind.convert.memberSeeme.MemberSeemeConvert;
import com.moxiao.yfjh.module.blind.dal.dataobject.memberSeeme.MemberSeemeDO;
import com.moxiao.yfjh.module.blind.service.memberSeeme.MemberSeemeService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import java.io.IOException;
import java.util.Collection;
import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@Tag(name = "管理后台 - 相亲会员看过我")
@RestController
@RequestMapping("/blind/member-seeme")
@Validated
public class MemberSeemeController {

    @Resource
    private MemberSeemeService memberSeemeService;

    @PostMapping("/create")
    @Operation(summary = "创建相亲会员看过我")
    @PreAuthorize("@ss.hasPermission('blind:member-seeme:create')")
    public CommonResult<Long> createMemberSeeme(@Valid @RequestBody MemberSeemeCreateReqVO createReqVO) {
        return success(memberSeemeService.createMemberSeeme(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新相亲会员看过我")
    @PreAuthorize("@ss.hasPermission('blind:member-seeme:update')")
    public CommonResult<Boolean> updateMemberSeeme(@Valid @RequestBody MemberSeemeUpdateReqVO updateReqVO) {
        memberSeemeService.updateMemberSeeme(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除相亲会员看过我")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('blind:member-seeme:delete')")
    public CommonResult<Boolean> deleteMemberSeeme(@RequestParam("id") Long id) {
        memberSeemeService.deleteMemberSeeme(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得相亲会员看过我")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('blind:member-seeme:query')")
    public CommonResult<MemberSeemeRespVO> getMemberSeeme(@RequestParam("id") Long id) {
        MemberSeemeDO memberSeeme = memberSeemeService.getMemberSeeme(id);
        return success(MemberSeemeConvert.INSTANCE.convert(memberSeeme));
    }

    @GetMapping("/list")
    @Operation(summary = "获得相亲会员看过我列表")
    @Parameter(name = "ids", description = "编号列表", required = true, example = "1024,2048")
    @PreAuthorize("@ss.hasPermission('blind:member-seeme:query')")
    public CommonResult<List<MemberSeemeRespVO>> getMemberSeemeList(@RequestParam("ids") Collection<Long> ids) {
        List<MemberSeemeDO> list = memberSeemeService.getMemberSeemeList(ids);
        return success(MemberSeemeConvert.INSTANCE.convertList(list));
    }

    @GetMapping("/page")
    @Operation(summary = "获得相亲会员看过我分页")
    @PreAuthorize("@ss.hasPermission('blind:member-seeme:query')")
    public CommonResult<PageResult<MemberSeemeRespVO>> getMemberSeemePage(@Valid MemberSeemePageReqVO pageVO) {
        PageResult<MemberSeemeDO> pageResult = memberSeemeService.getMemberSeemePage(pageVO);
        return success(MemberSeemeConvert.INSTANCE.convertPage(pageResult));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出相亲会员看过我 Excel")
    @PreAuthorize("@ss.hasPermission('blind:member-seeme:export')")
    @OperateLog(type = EXPORT)
    public void exportMemberSeemeExcel(@Valid MemberSeemeExportReqVO exportReqVO,
              HttpServletResponse response) throws IOException {
        List<MemberSeemeDO> list = memberSeemeService.getMemberSeemeList(exportReqVO);
        // 导出 Excel
        List<MemberSeemeExcelVO> datas = MemberSeemeConvert.INSTANCE.convertList02(list);
        ExcelUtils.write(response, "相亲会员看过我.xls", "数据", MemberSeemeExcelVO.class, datas);
    }

}
